﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Huirui.Cavan.Core.Persistent;
using Huirui.Cavan.Domain.MainBoundedContext.SearchModule;
using Huirui.Cavan.Core.MyLinq;
using Huirui.Cavan.Core.Extension;

namespace Huirui.Cavan.Domain.MainBoundedContext.SystemModule
{
    public class SystemConfigSpecification : ISpecification<SystemConfig, SystemConfigSearch>
    {
        #region ISpecification<SystemConfig,SystemConfigSearch> Members

        public SystemConfigSearch SearchParams
        {
            get;
            set;
        }

        #endregion

        #region ISpecification<SystemConfig> Members

        public System.Linq.Expressions.Expression<Func<SystemConfig, bool>> Expression
        {
            get
            {
                IQueryBuilder<SystemConfig> queryBuilder = QueryBuilder.Create<SystemConfig>();

                if (null != SearchParams)
                {
                    if (SearchParams.CorporationCode.IsNotEmpty())
                    {
                        queryBuilder = queryBuilder.Equals(sc => sc.Corporation.Id, SearchParams.CorporationCode);
                    }
                    if (SearchParams.Item.IsNotEmpty())
                    {
                        queryBuilder = queryBuilder.Equals(sc => sc.Item, SearchParams.Item);
                    }
                }

                return queryBuilder.Expression.Expand();
            }
        }

        #endregion
    }
}
